package com.ruoyi.index.service.impl;

import com.cyl.manager.ums.domain.entity.Member;
import com.cyl.manager.ums.service.MemberService;
import com.github.pagehelper.PageHelper;
import com.ruoyi.index.domain.FhIndexPostcomments;
import com.ruoyi.index.domain.PostcommentsLike;
import com.ruoyi.index.dto.FhIndexPostcommentsLikeDto;
import com.ruoyi.index.mapper.FhIndexPostcommentsMapper;
import com.ruoyi.index.mapper.IndexPostcommentsLikeMapper;
import com.ruoyi.system.domain.FhUser;
import com.ruoyi.system.domain.FhUserDto;
import com.ruoyi.system.service.IFhUserService;
import com.ruoyi.web.core.config.LocalUserInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 点赞评论 Service业务层处理
 */
@Service
public class IndexPostcommentsLikeService
{
    @Autowired
    private IndexPostcommentsLikeMapper indexPostcommentsLikeMapper;
    @Autowired
    private FhIndexPostcommentsMapper indexPostcommentsMapper;

    @Autowired
    private IFhUserService fhUserService;

    //点赞评论
    public int likePostcomments(PostcommentsLike postcommentsLike) {
        return indexPostcommentsLikeMapper.likePostcomments(postcommentsLike);
    }

    //取消点赞评论
    public int unlikePostcomments(PostcommentsLike postcommentsLike) {
        return indexPostcommentsLikeMapper.unlikePostcomments(postcommentsLike);
    }

    //查询点赞状态
    public PostcommentsLike getLikeStatus(PostcommentsLike postcommentsLike) {
        return indexPostcommentsLikeMapper.getLikeStatus(postcommentsLike);
    }

    public List<FhIndexPostcommentsLikeDto> notificationList(FhUserDto fhUserDto,Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        Long userId = LocalUserInfoUtil.getLocalUserInfo().getId();
        //查询当前评论列表
        List<FhIndexPostcomments> commentsList = indexPostcommentsMapper.selectList(userId);
        for (FhIndexPostcomments indexPostcomments : commentsList) {
            List<FhIndexPostcommentsLikeDto> list = indexPostcommentsLikeMapper.notificationList(indexPostcomments.getId());
            for (FhIndexPostcommentsLikeDto likeDto : list) {
                FhUser fhUser = fhUserService.selectFhUserById(likeDto.getUserId());
                likeDto.setAvatar(fhUser.getImage());
                likeDto.setLikeTop("点赞了你的消息");
            }
            return list;
        }
        return new ArrayList<>();

    }
}
